Warning: preg_match() [function.preg-match]: Unknown modifier '/' problem

Posted by SonOfOmer on Stack Overflow See other posts from Stack Overflow or by SonOfOmer
Published on 2011-06-20T22:28:53Z Indexed on 2012/09/24 15:37 UTC
Read the original article Hit count: 405

Filed under:
|
|
|

I am building custom implementation of php MVC routing engine, and I have custom routes like one in $routes array below.

Each time when I send asynchronous GET request like xmlhttp.open("GET","someurl"); I get following message

Warning: preg_match() [function.preg-match]: Unknown modifier '/' problem 

but with synchronous (normal) request it all works fine

<?php
$routes = array(
array('url' => '/^someurl$/', 'controller' => 'somecontroller', 'view' => 'someview')
);
$url = $_SERVER['REQUEST_URI']; 
$url = substr( $url, 1 );
$params = array();

        $route_match = false;
        foreach($routes as $urls => $route)
        {                           
            if(preg_match($route['url'], $url, $matches))
            {
                $params = array_merge($params, $matches);
                $route_match = true;                            
                break;                  
            }                       
        }

        require_once(CONTROLLER_PATH.$route['controller'].'.php');      
?>

string(11) "/^someurl$/" is the result of var_dump($route['url']);

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex